package net.xdclass.strategy;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * 功能描述
 *
 * @author ASUS
 * @date 2024/07/27  23:12
 */
public class ShardingTableConfig {
    /**
     * 存储数据表位置编号
     */
    private static final List<String> tableSuffixList = new ArrayList<>();

    private static Random random = new Random();

    //配置启用那些库的前缀
    static{
        tableSuffixList.add("0");
        tableSuffixList.add("1");

    }

    /**
     * 获取随机的后缀
     * @return
     */
    public static String getRandomTableSuffix(String code){
        int hashCode = code.hashCode();
        int index = Math.abs(hashCode) % tableSuffixList.size();
        //随机
        //int index = random.nextInt(tableSuffixList.size());
        return tableSuffixList.get(index);
    }

}
